<?php declare(strict_types=1);

$di = \application\units\Di::getInstance();

$params = [
    'id' => explode(',', (string)$di->request->params('id')),
];

if (!$params['id']) throw new LogicException('id参数不能为空');

$rows = $di->db->query('select * from admin_resource');
$di->tree->init($rows);
$childrenId = [];
foreach ($params['id'] as $id) {
    // 将菜单以及菜单的下级删除
    $childrenId = array_merge($childrenId, $di->tree->getChildrenIds($id, true));
}

$stat = $di->db->execute('delete from admin_resource where id in (:id)', [
    'id' => $childrenId,
]);

if ($stat->rowCount() <= 0) throw new PDOException('操作失败');

return [];